import time
import cv2
import numpy as np
import sys

# Wimg = cv2.imread('1.jpg') #白色背景显示的图片 Wimg为white-img缩写
Wimg = cv2.imread('1.png') #白色背景显示的图片 Wimg为white-img缩写
Wimg = cv2.cvtColor(Wimg,cv2.COLOR_BGR2GRAY)
Wimg = cv2.cvtColor(Wimg,cv2.COLOR_GRAY2BGRA)

# Bimg = cv2.imread('2.jpg') #黑色背景显示的图片 Bimg为black-img缩写
Bimg = cv2.imread('2.png') #黑色背景显示的图片 Bimg为black-img缩写
Bimg = cv2.cvtColor(Bimg,cv2.COLOR_BGR2GRAY)
Bimg = cv2.cvtColor(Bimg,cv2.COLOR_GRAY2BGRA)

h1,w1 = Wimg.shape[:2]
h2,w2 = Bimg.shape[:2]
h = min([h1,h2])
w = min([w1,w2])
# 奇数列行，为了交错排列两张图片
if h % 2 == 0:
    h -= 1
if w % 2 == 0:
    w -= 1

# 降低对比度，并提高亮度
Bimg = cv2.addWeighted(Bimg,0.3,0,0,100)

Wimg = cv2.resize(Wimg,(w,h))
Bimg = cv2.resize(Bimg,(w,h))
Rimg = np.zeros([h,w,4],dtype=np.uint8)
flag = True
print(h,w)
for y in range(h):
    for x in range(w):
        if flag:
            # 显示白色图片
            Rimg[y,x] = Wimg[y,x]*0.3
            Rimg[y,x,3] = 255-Wimg[y,x,0]
            flag = False
        else:
            # 显示黑色图片
            Rimg[y,x] = Bimg[y,x]
            Rimg[y,x,3] = Bimg[y,x,0]
            flag = True

cv2.imwrite('result.png',Rimg, [cv2.IMWRITE_PNG_COMPRESSION, 0])
